<template>
  <a-modal
    title="专利师稿件确认"
    v-model="visible"
    centered
    :width="500"
    @ok="saveFill"
    @cancel="onCancel"
  >
    <a-form-model
      ref="form"
      :model="form"
      :rules="form.status2 == 35 ? rules : rules2"
    >
      <a-form-model-item>
        <a-alert>
          <template slot="message">
            点击下载专利师撰写的最新材料
          </template>
          <template slot="description">
            <a-button type="link" icon="download" @click="download(fileOpts.patenteer_file)">
              <ellipsis :length="20">
                {{ fileOpts.patenteer_filename }}
              </ellipsis>
            </a-button>
          </template>
        </a-alert>
      </a-form-model-item>
      <a-form-model-item prop="status2">
        <a-radio-group v-model="form.status2">
          <a-radio :value="35">需要修改</a-radio>
          <a-radio :value="36">定稿</a-radio>
        </a-radio-group>
      </a-form-model-item>
      <a-form-model-item v-if="form.status2 == 35" prop="notes">
        <a-textarea placeholder="请输入需要修改的原因" v-model="form.notes" :rows="4"></a-textarea>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
  import { getFill } from '@/api/business'
  import Ellipsis from '@/components/Ellipsis/Ellipsis'

  export default {
    components: { Ellipsis },
    props: {
      fillKey: {
        type: String,
        default: ''
      }
    },
    name: 'PatentModal',
    data () {
      return {
        visible: false,
        form: {},
        fileOpts: {},
        rules: {
          notes: [{ required: true, message: '要求修改，必须填写原因，方便专利师修改', trigger: 'blur' }]
        },
        rules2: {
          status2: [{ required: true, message: '要求修改，必须填写原因，方便专利师修改', trigger: 'blur' }]
        }
      }
    },
    created () {
      this.getInfo(this.fillKey)
    },
    methods: {
      onCancel () {
        this.visible = false
        this.$emit('cancel', this.visible)
      },
      getInfo (key) {
        const app = this
        getFill(key).then(res => {
          app.fileOpts['patenteer_file'] = res.result.patenteer_file
          app.fileOpts['patenteer_filename'] = res.result.patenteer_filename
        }).finally(() => {
          app.visible = true
        })
      },
      download (url) {
        window.open(url)
      },
      saveFill () {
         this.$refs.form.validate(valid => {
           if (valid) {
             this.$emit('submit', this.form)
           } else {
             return false
           }
         })
      }
    }
  }
</script>

<style scoped>

</style>
